<?php

/********************************************************/
/* CiroxX(tm)(c) v.5 Content Management System          */
/* ===========================================          */
/* Basecode (c) by Francisco Burzi                      */
/* Powered by: Coldcut (P.A.) webmaster@cybertipps.com  */
/* http://www.cybertipps.com                            */
/* Copyright © 2006 - 2012 by CT_Dev.                   */
/********************************************************/

if(!defined('CX_IS_MOD_SEARCH'))die('You can\'t access this file directly!');

if( ! cx_function_exists( 'cx_sdown_cats' ) )
{
        /**
         * cx_sdown_cats()
         *
         * @param mixed $module_data
         * @return
         */
        function cx_sdown_cats( $module_data )
        {
                global $db;

                $sql = "SELECT `id`, `title`, `alias`, `who_view`, `groups_view` FROM `" . CX_PREFIXLANG . "_" . $module_data . "_categories` WHERE `status`=1";
                $result = $db->sql_query( $sql );

                $list = array();
                while ( $row = $db->sql_fetchrow( $result ) )
                {
                        if ( cx_set_allow( $row['who_view'], $row['groups_view'] ) )
                        {
                                $list[$row['id']] = array(
                                        'id' => ( int )$row['id'],
                                        'title' => $row['title'],
                                        'alias' => $row['alias']
                                );
                        }
                }
                return $list;
        }
}

$list_cats = cx_sdown_cats( $m_values['module_data'] );
$in = implode( ",", array_keys( $list_cats ) );

$sql = "SELECT SQL_CALC_FOUND_ROWS `alias`,`title`,`description`, `introtext`, `catid`
FROM `" . CX_PREFIXLANG . "_" . $m_values['module_data'] . "`
WHERE `catid` IN (" . $in . ")
AND (" . cx_like_logic( 'title', $dbkeyword, $logic ) . "
OR " . cx_like_logic( 'description', $dbkeyword, $logic ) . "
OR " . cx_like_logic( 'introtext', $dbkeyword, $logic ) . ")
LIMIT " . $pages . "," . $limit;

$tmp_re = $db->sql_query( $sql );

$result = $db->sql_query( "SELECT FOUND_ROWS()" );
list( $all_page ) = $db->sql_fetchrow( $result );

if ( $all_page )
{
        $link = CX_BASE_SITEURL . "index.php?" . CX_LANG_VARIABLE . "=" . CX_LANG_DATA . "&amp;" . CX_NAME_VARIABLE . "=" . $m_values['module_name'] . '&amp;' . CX_OP_VARIABLE . '=';

        while ( list( $alias, $tilterow, $content, $introtext, $catid ) = $db->sql_fetchrow( $tmp_re ) )
        {
                $content = $content . ' ' . $introtext;

                $result_array[] = array(
                        'link' => $link . $list_cats[$catid]['alias'] . '/' . $alias,
                        'title' => BoldKeywordInStr( $tilterow, $key, $logic ),
                        'content' => BoldKeywordInStr( $content, $key, $logic )
                );
        }
}

?>